package cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.base;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.R;
import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.utils.Constance;
import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.utils.SystemStatusManager;

/**
 * Created by dell on 2017/10/24.
 */

public abstract class BaseActivity extends AppCompatActivity {

    protected SharedPreferences mSharedPreferences;
    protected SharedPreferences.Editor mEditor;
    protected Gson gson = null ;
    protected com.nostra13.universalimageloader.core.ImageLoader mImageLoader;
    protected DisplayImageOptions mOptions;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mSharedPreferences = getSharedPreferences(Constance.SHARE_KEY, MODE_PRIVATE);
        mEditor = mSharedPreferences.edit();
        gson = new Gson();
        if (setLayoutId() != 0) {
            if (setLayoutId() == R.layout.activity_welcome || setLayoutId() == R.layout.activity_star){
                requestWindowFeature(Window.FEATURE_NO_TITLE);
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }else {
                setTranslucentStatus();
            }
            setContentView(setLayoutId());
        }
        initView();
        initData();
      //  setTranslucentStatus();

    }
    protected void setTranslucentStatus() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // 透明状态栏
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // 透明导航栏
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            SystemStatusManager tintManager = new SystemStatusManager(this);
            tintManager.setStatusBarTintEnabled(true);
            // 设置状态栏的颜色
            tintManager.setStatusBarTintResource(R.color.mainColor);
            getWindow().getDecorView().setFitsSystemWindows(true);
        }
    }
    protected abstract int setLayoutId();
    protected  abstract void initView();
    protected  abstract void initData();


}
